#include <bits/stdc++.h>
using namespace std;

const int N = 3010;
int n, m;
vector<pair<int, int>> g[N];
int f[N][N];  // f[x][k] = 以x为根的子树中选k个用户的最大盈利（可能为负）
int cnt[N];

void dfs(int x) {
    f[x][0] = 0; // 不选任何用户，收益为0

    for (auto [y, cost] : g[x]) {
        dfs(y);
        cnt[x] += cnt[y];
        // 合并子树：先复制 f[x]
        for (int j = cnt[x]; j >= 0; j--) {
            for (int k = 0; k <= cnt[y]; k++) {
                f[x][j] = max(f[x][j], f[x][j - k] + f[y][k] - cost);
            }
        }
    }
}

void solve() {
    cin >> n >> m;

    for (int x = 1; x <= n - m; x++) {
        int k; cin >> k;
        for (int i = 0; i < k; i++) {
            int y, c; cin >> y >> c;
            g[x].emplace_back(y, c);
        }
    }

    memset(f, -0x3f, sizeof f);
    for (int i = n - m + 1; i <= n; i++) {
        int val; cin >> val;
        f[i][1] = val;
        cnt[i] = 1;
    }
    for (int i = 1;i <= n;i++) f[i][0] = 0;

    dfs(1);

    for (int k = m; k >= 0; k--) {
        if (f[1][k] >= 0) {
            cout << k << "\n";
            return;
        }
        }
    }


signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}